#include "pthreadPool.h"

int initThreadPool(threadPool_t * pthreadPool,int workerNum){
    initTidArr(&pthreadPool->tidArr,workerNum);
    initQueue(&pthreadPool->taskQueue);
    pthread_mutex_init(&pthreadPool->mutex,NULL);
    pthread_cond_init(&pthreadPool->cond,NULL);
    printf("ThreadPool init OKay.\n");
    return 0;
}

int initTcp(char *ip,char *port){
    int sockFd = socket(AF_INET,SOCK_STREAM,0);
    int flag = 1;
    setsockopt(sockFd,SOL_SOCKET,SO_REUSEADDR,&flag,sizeof(flag));
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(atoi(port));
    addr.sin_addr.s_addr = inet_addr(ip);
    int ret_bind = bind(sockFd,(struct sockaddr*)&addr,sizeof(addr));
    ERROR_CHECK(ret_bind,-1,"bind");
    listen(sockFd,50);
    printf("TCP init OKay.\n");
    return sockFd;
}

int epollAdd(int epfd,int fd){
    struct epoll_event event;
    event.data.fd = fd;
    event.events = EPOLLIN;
    epoll_ctl(epfd,EPOLL_CTL_ADD,fd,&event);
    return 0;
}

int epollDel(int epfd,int fd){
    epoll_ctl(epfd,EPOLL_CTL_DEL,fd,NULL);
    return 0;
}
